﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using SimpleRest.Serialization;
using SimpleRest.WebTest.Services;

namespace SimpleRest.Tests
{
    [TestClass]
    public class DataAnnotations
    {
        [TestMethod]
        public void FAIL_NonRecursiveValidation_IdMission()
        {
            var item = new TestClassA();
            ValidationContext context = new ValidationContext(item, null, null);
            Validator.ValidateObject(item, context);
        }

        [TestMethod]
        public void Pass_NonRecursiveValidation_ProvidedId_ProvidedItems()
        {
            var item = new TestClassA();
            item.Id = "123";
            item.Items = new List<TestClassB>() { new TestClassB() };
            item.Item = new TestClassB();

            ValidationContext context = new ValidationContext(item, null, null);
            Validator.ValidateObject(item, context, true);
        }

        [TestMethod]
        public void Fail_RecursiveValidation_ProvidedId_ProvidedItem_ProvidedInvalidTestClassB()
        {
            var item = new TestClassA();
            item.Id = "123";
            item.Items = new List<TestClassB>() { new TestClassB() };
            item.Item = new TestClassB() { Name = "jerrod", Age = 12 };

            SimpleRest.Core.Extensions.ValidationUtility.RecursiveValidation(item);
        }
    }

    public class TestClassA
    {
        [Required]
        public string Id { get; set; }

        [Required]
        public List<TestClassB> Items { get; set; }

        [Required]
        public TestClassB Item { get; set; }

        public string Description { get; set; }
    }

    public class TestClassB
    {
        [Range(0, 150)]
        public int Age { get; set; }

        [Required]
        public string Name { get; set; }

        public string Description { get; set; }
    }
}
